#ifndef NRPSTG_FONT_H
#define	NRPSTG_FONT_H

#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H

#include <GL/gl.h>
#include <GL/glu.h>
#include <string>
#include <boost/unordered_map.hpp>

#include "GuiWidget.h"

using namespace std;
using namespace boost;

class FontFace {
private:
    float _height;
    float* _widths;
    GLuint* _textures;
    GLuint _lists;

public:
    FontFace(int height);
    virtual ~FontFace();

    float h();
    GLuint texture(int ch);
    GLuint list(int ch);

    void set_width(int ch, float w);

    float get_width(int ch);
    float get_str_width(const string& text);
    void str_to_width(const string& text, string& out, float width);
};

class FontManager {
private:
    FT_Library _library;
    unordered_map<string, FontFace*> _faces;
    FontFace* _current;

    int _next_p2(int p);
public:
    FontManager();
    virtual ~FontManager();

    void add_face(const string& name, const string& path, int height);
    void select_face(const string& name);

    void fit_text(const string& text, string& out, float fit);
    void render(const string& text, int x, int y, float zindex, float* mw, float* mh);
    void render(const string& text, int x, int y, int w, int h, float zindex, GUI_ALIGN align, GUI_VALIGN valign, float* mw, float* mh);
};

#endif	/* NRPSTG_FONTMANAGER_H */

